﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL.Classes;
using DAL;

namespace Business.Classes
{
    public class PostNewBusiness
    {
        PostNewDAL postNewDAL = new PostNewDAL();

        public PostNew getPostNewByID(int id)
        {
            try
            {
                return postNewDAL.getPostNewByID(id);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public List<PostNew> getAllPostNew()
        {
            try
            {
                return postNewDAL.getAllPostNew();
            }
            catch (Exception)
            {
                throw;
            }
        }
        public List<PostNew> getAllPostNewByUser(Usuario user)
        {
            try
            {
                return postNewDAL.getAllPostNewByUser(user);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void deletePostnew(PostNew postNew)
        {
            try
            {
                postNewDAL.deletePostnew(postNew);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void updatePostnew(PostNew postNew, List<Tag> listTag)
        {
            try
            {
                postNewDAL.updatePostnew(postNew, listTag);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void updatePostnew(PostNew postNew)
        {
            try
            {
                postNewDAL.updatePostnew(postNew);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public void InsertPostnew(PostNew postNew)
        {
            try
            {
                postNewDAL.InsertPostnew(postNew);
            }
            catch (Exception)
            {
                throw;
            }
        }
        public void InsertPostnew(PostNew postNew, List<Tag> listTag)
        {
            try
            {
                postNewDAL.InsertPostnew(postNew, listTag);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public bool permiteImagem(string extencaoImagem)
        {
            try
            {
                string[] extecoesPermitidas = { "jpg", "bmp", "gif", "png", "jepg" };
                
                for (int i = 0; i < extecoesPermitidas.Length; i++)
                {
                    if (extencaoImagem.ToLower() == extecoesPermitidas[i])
                        return true;
                }

                return false;
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public List<PostNew> getPostNewByParameters(string conteudo, string user, DateTime data, List<Tag> listTags)
        {
            try
            {
                return postNewDAL.getPostNewByParameters(conteudo, user, data, listTags);
            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public List<PostNew> getPostNewByContent(string conteudo)
        {
            try
            {
                return postNewDAL.getPostNewByParameters(conteudo);
            }
            catch (Exception)
            {

                throw;
            }
        }


        public List<PostNew> GetTopPostNews(int top)
        {
            try
            {
                return postNewDAL.GetTopPostNews(top).OrderByDescending(x=> x.data).ToList();
            }
            catch (Exception)
            {
                
                throw;
            }
        }
    }
}
